﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;

<<<<<<< HEAD
namespace List
{
    public class ArrayList<T>
    {
        private T[] arry;
        public ArrayList(int size)
        {
            arry = new T[size];
        }
        public void AddItem(int n, T x)
        {
            arry[n] = x;
        }
        public void Foreach(Action<T> act)
        {
            for(int i = 0; i < arry.Length; i++)
            {
                act(arry[i]);
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            ArrayList<int> list = new ArrayList<int>(10);
            int sum = 0;int max = 0;int min = Int16.MaxValue;
            Random ran = new Random();
            for (int i = 0; i < 10; i++)
            {
                list.AddItem(i, ran.Next(0,20));
            }
            list.Foreach(s => Write(s + " "));
            WriteLine();
            list.Foreach(s => sum += s);
            WriteLine("和为："+sum);
            list.Foreach(s=> { if (max < s) max = s; });
            list.Foreach(s => { if (min > s) min = s; });
            WriteLine("最小值为：" + min);
            WriteLine("最大值为：" + max);
            ReadKey();
=======
namespace ConsoleApplication2
{
    class Program
    {
        static bool IfPrime(int n)
        {
            bool flag = true;
            for(int i=2;i<= n/2; i++)
            {
                if (n % i == 0)
                {
                    flag = false;
                    break;
                }
            }
            return flag;
        }

        static void Main(string[] args)
        {
            while (true)
            {
                int num;
                int i = 2;
                Write("输入你想检验的自然数：");
                num = Int32.Parse(ReadLine());
                Write("素数因子为：");
                int x = num / 2;
                if (IfPrime(num))
                {
                    Write(num);
                    WriteLine();
                    continue;
                }
                while (i<=x)
                {
                    if (IfPrime(i)==true && num % i == 0)
                    {
                        Write(i+" ");
                        num = num / i;
                    }
                    else if (IfPrime(i) == false||num%i!=0)
                    {
                        i++;
                    }
                }
                //Write(num);
                WriteLine();
            }
>>>>>>> 5ef73b757075c80cc034353a7bb5d41a841de922
        }
    }
}
